/**
 * Created by yindu on 2018/12/17.
 */
var express = require('express');
var router = express.Router();
var db = require('../libs/mysql.js');
//统一返回格式
var res_Data;
router.use( function(req, res, next) {
    res_Data = {
        code: 0,
        message: ''
    }
    next();
});
router.get('/',function (req,res) {// /api
    db.query(`SELECT * FROM home`,(err,data)=>{
        if(err){
            res.send('课程列表').end();
        }else {
            res.json(data);
        }
    })
})
router.get('/home_del',function (req,res) {// /api
    var id = req.query.id;
    db.query(`delete from home_details where home_id = ${id};`,(err)=>{
        if(err){
            res.send('删除课程报名人详情').end();
        }else {
            db.query(`delete from home where id = ${id};`,(err,data)=>{
                if(err){
                    res.send('删除课程').end();
                }else {
                    res_Data.message = '删除成功';
                    res.json(res_Data);
                    return;
                }
            })
        }
    })
})

router.use('/home_add',require('./home_add'));//添加课程
router.use('/home_addPeople',require('./home_addPeople'));//添加报名人
router.use('/home_amend',require('./home_amend'));//修改课程
router.use('/home_details',require('./home_details'));//报名人列表

module.exports = router;